﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Core
{
	public class ListDifferencer : ListDifferencer<object>
	{
		public ListDifferencer( IEnumerable<object> left, IEnumerable<object> right ) : base( left, right )
		{}
	}

	public class ListDifferencer<T>
	{
		readonly List<T> left, right;

		public ListDifferencer( IEnumerable<T> left, IEnumerable<T> right )
		{
			this.left = new List<T>( left );
			this.right = new List<T>( right );
		}

		public List<T> GetLeftDifference()
		{
			List<T> temp = new List<T>( left );
			temp.RemoveAll( LeftRemove );
			return temp;
		}

		public List<T> GetRightDifference()
		{
			List<T> temp = new List<T>( right );
			temp.RemoveAll( RightRemove );
			return temp;
		}

		bool LeftRemove( T item )
		{
			return right.Contains( item );
		}

		bool RightRemove( T item )
		{
			return left.Contains( item );
		}
	}}
